//package com.manage.web.config;
//
//import org.apache.zookeeper.WatchedEvent;
//import org.apache.zookeeper.Watcher;
//import org.apache.zookeeper.ZooKeeper;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.concurrent.CountDownLatch;
///**
// * 测试zookeeper连接
// * @author duaiyu
// * @version V1.0
// * @date 2022/2/20
// * 来源：bilibili
// */
//@Configuration
//public class ZookeeperConfig {
//    @Value("${zookeeper.address}")
//    private String connectString;
//    @Value("${zookeeper.timeout}")
//    private int timeout;
//
//    @Bean(name = "zkClient")
//    public ZooKeeper zkClient() {
//        ZooKeeper zooKeeper = null;
//        try {
//            final CountDownLatch countDownLatch = new CountDownLatch(1);
//            zooKeeper = new ZooKeeper(connectString, timeout, new Watcher() {
//                @Override
//                public void process(WatchedEvent event) {
//                    if (Event.KeeperState.SyncConnected == event.getState()) {
//                        //如果收到了服务端的响应事件，连接成功
//                        countDownLatch.countDown();
//                    }
//                }
//            });
//            countDownLatch.await();
//            System.out.println("zk连接成功");
//        } catch (Exception e) {
//        }
//        return zooKeeper;
//    }
//}
